home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / shell / execute_upd.lha / Execute / strsep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-28  |  577 b   |  45 lines

  1. #include <string.h>
  2.  
  3. char *strsep (char **stringp, char *delim)
  4. {
  5.   char *save_string, *brk;
  6.  
  7.   if ((save_string = *stringp) == NULL)
  8.     return (NULL);
  9.  
  10.   if (brk = strpbrk (*stringp, delim))
  11.     {
  12.       *brk = '\0';
  13.       
  14.       *stringp = brk + 1;
  15.  
  16.     }
  17.   else
  18.     {
  19.       *stringp = NULL;
  20.     }
  21.   
  22.   return (save_string);
  23. }
  24.  
  25.  
  26. #ifdef TEST
  27.  
  28. #include <stdio.h>
  29.  
  30. main()
  31. {
  32.   char *string = "one two three four five";
  33.  
  34.   while (string)
  35.     {
  36.       char *token;
  37.  
  38.       while ((token = strsep (&string, " ")) && (*token == '\0')) ;
  39.  
  40.       printf ("%s\n", token);
  41.     }
  42. }
  43.  
  44. #endif
  45.